
Imports Microsoft.Ink
Imports System.Drawing
Imports System.Runtime.Remoting.Messaging

' The original stroke object is managed by its owner ink class.  This feature
' prevents the class from being serializable.  This class was created to
' implement only the basic parts of a real stroke, while at the same time
' maintaining its serializability.
<Serializable()> Public Class UnmanagedStroke
    ' Array of all the points that a stroke covers.
    Public Points As Point()

    ' The color of the stroke.
    Public Color As Color
    ' The width of the stroke.
    Public Width As Integer
    Public IconName As String
    Public IconX As Integer
    Public IconY As Integer
    Public MyType As String
    Public IconID As String
    Public OriginalID As String
    Public Image As String
    Public ScreenShot As String
    ' Client code calls this static function when they want to create a new
    ' object of this class with all the attributes of the passed stroke.
    Public Shared Function UnmanageInk(ByRef Managed As Stroke, ByVal strIP As String) As UnmanagedStroke
        ' Create the new unmanaged cousin of the stroke given us.
        Dim Unmanaged As New UnmanagedStroke(strIP)

        With Unmanaged
            ' Copy the points from the real stroke.
            .Points = Managed.GetPoints()

            ' Get the color from the real stroke.
            .Color = Managed.DrawingAttributes.Color
            ' Get the width from the real stroke.
            .Width = Managed.DrawingAttributes.Width
        End With

        ' Return the new unmanaged cousin to the client code.
        Return Unmanaged
    End Function

    ' Client code calls this static function when they want to create a new
    ' managed stroke from an existing version of its unmanaged cousin.
    Public Shared Function ManageInk(ByVal Unmanaged As UnmanagedStroke) As Stroke
        ' We will need an ink instance to create the stroke.
        Dim Ink As New Ink
        ' The actual stroke object.  To be created using the ink object.
        Dim Managed As Stroke

        With Unmanaged
            ' Use the ink object to create a new stroke from the points
            ' passed to us from the unmanaged cousin.
            Managed = Ink.CreateStroke(.Points)

            ' Set the color of the new stroke.
            Managed.DrawingAttributes.Color = .Color
            ' Set the width of the new stroke.
            Managed.DrawingAttributes.Width = .Width
        End With

        ' Return the new managed stroke to the client code.
        Return Managed
    End Function

    'Public Sub New()
    '   CallContext.FreeNamedDataSlot("ObservedIP")
    'End Sub
    Public Sub New(ByVal strIP As String)
        CallContext.SetData("ObservedIP", strIP)
    End Sub
End Class
